<?php

namespace app\admin\controller;

use app\admin\model\AuthRule;
use app\common\controller\Base;
use app\common\traits\Gate;
use think\Loader;

/**
 * Class Admin
 * @package app\admin\controller
 * @author: Huang
 * @internal
 */
class Admin extends Base
{
    use Gate;
    use \app\common\traits\Common;
    /**
     *初始化系统
     */
    protected function _initialize()
    {
        parent::_initialize();
        if(isIeBrowser()){
            $this->redirect(url('admin/login/ie'));
        }
        //session不存在时，不允许直接访问
        if (defined('UID')) return;
        define('UID', is_login());
        if (empty(session('user_weixin'))) {
            $current_url = get_current_url();
        }
        if (!UID && is_wechat_browser()) $this->login($current_url);
        if (!UID) $this->redirect(url('admin/login/login'));
        $auth = AuthRule::getInstance();
        $id_curr = $auth->get_url_id();//获取当前菜单的id
        if (!$auth->check_auth($id_curr)) $this->error('未授权访问', url('admin/index/index'));
        //获取有权限的菜单tree
        $menus = $auth->get_admin_menus();
        $this->assign('nowmens', $id_curr);
        $this->assign('menus', $menus);
        /*获取提醒数据*/
//        $this->assign('controller', Loader::parseName($this->request->controller()));
//        $this->assign('module', Loader::parseName($this->request->module()));
    }
}